package org.example.lc;

/**
 * @author carol
 * 太慢了这个方法，推荐双指针吧
 **/
public class MoveZeroes {

    public static void moveZeroes(int[] nums) {
        int length = nums.length-1;
        for(int i = 0;i <=length;i++){
            if(nums[i]==0){
                int j = i;
                while(j<length){
                    nums[j] = nums[j+1];
                    j++;
                }
                nums[length]=0;
                length--;
                i--;
            }
        }
    }

    public static void main(String[] args) {
        int[] nums = {0,0,1};
        moveZeroes(nums);
        for(int i = 0;i<nums.length;i++){
            System.out.println(nums[i]);
        }
    }
}
